package com.eecs393.drymouth;

import com.eecs393.drymouth.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.content.DialogInterface;
import android.content.Intent;

public class EnterLogin extends Activity implements OnClickListener
{
	private EditText userName;
	private EditText password;
	private boolean failed_login = false;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        userName = (EditText) this.findViewById(R.id.EditText_username);
        password = (EditText) this.findViewById(R.id.EditText_password);
        Button button = (Button) this.findViewById(R.id.Button_submitlogin);
        
        button.setOnClickListener(this);
        
        Bundle extras = this.getIntent().getExtras();
        if(extras != null)
        {
        	failed_login = extras.getBoolean("failed_login");
        }
        if(failed_login)
        {
        	AlertDialog.Builder adb = new AlertDialog.Builder(this);
			adb.setTitle("Invalid Login!");    		
			
			String body = "Please re-enter username and password!";
			
			adb.setMessage(body);
			adb.setCancelable(true);
			adb.setNeutralButton("OK", new DialogInterface.OnClickListener(){
				@Override
				public void onClick(DialogInterface dialog, int which){
					dialog.dismiss();
				}
			});
			AlertDialog ad = adb.create();
			ad.show();
        }
    }
    
    public void onClick(View v)
    {
    	//assert symptomSet != null;
    	String username = userName.getText().toString();
    	String pass = password.getText().toString();
    	//symptoms = symptoms.replace(',', '~');
    	//symptoms = symptoms.replace(' ', '_');
    	Intent submitLogin = new Intent(this, SubmitLogin.class);
    	submitLogin.putExtra("usernamekey", username);
    	submitLogin.putExtra("passwordkey", pass);
    	this.startActivity(submitLogin);
    }
}
